package ae.pcfc.cldos.online.common.facade;

import ae.pcfc.cldos.online.common.UltimusConstants;
import ae.pcfc.cldos.online.common.clddb.domain.AppMetaData;
import ae.pcfc.cldos.online.common.clddb.domain.Process;
import ae.pcfc.cldos.online.common.clddb.domain.ServiceMaster;
import ae.pcfc.cldos.online.common.clddb.domain.manager.AppMetaDataDOM;
import ae.pcfc.cldos.online.common.clddb.domain.manager.ReviewCommentsDOM;
import ae.pcfc.cldos.online.common.etksdb.domain.manager.UserDomainObjectManager;
import ae.pcfc.cldos.online.common.manager.BuisnessValidationManager;
import ae.pcfc.cldos.online.common.manager.DataTransferManager;
import ae.pcfc.cldos.online.common.manager.FNPManager;
import ae.pcfc.cldos.online.common.manager.FileStorageManager;
import ae.pcfc.cldos.online.common.manager.GSEmployeeDetailsManager;
import ae.pcfc.cldos.online.common.manager.GsInfoManager;
import ae.pcfc.cldos.online.common.manager.TaskAndNotificationsManager;
import ae.pcfc.cldos.online.common.tscdb.domain.manager.TTscClientCompanyDOM;
import ae.pcfc.cldos.online.common.vo.TransferDataVO;
import ae.pcfc.cldos.online.common.vo.UserVO;
import ae.pcfc.cldos.online.wf.service.client.GenericVisaWF;
import ae.pcfc.cldos.online.wf.service.client.vo.appdata.EmploymentVisaAppInfoVO;
import ae.pcfc.cldos.online.wf.service.client.vo.base.LaunchIncedentVO;
import ae.pcfc.cldos.online.wf.service.client.vo.gvar.VisaSubmitGVarVO;

/**
 * 
 * @author arosa
 *
 */
public abstract class BaseProcesesFacade extends BaseFacade {

	protected AppMetaDataDOM appMetaDataDOM;
	protected GenericVisaWF genericVisaWF;
	protected FileStorageManager fileStorageManager;
	protected TTscClientCompanyDOM tTscClientCompanyDOM;
	protected GSEmployeeDetailsManager gsEmployeeDetailsManager;
	protected UserDomainObjectManager userDomainObjectManager;	
	protected TaskAndNotificationsManager taskAndNotificationsManager;
	protected FNPManager fnpManager;
	protected BuisnessValidationManager buisnessValidationManager;
	protected ReviewCommentsDOM reviewCommentsDOM;
	protected GsInfoManager gsInfoManager;
	protected DataTransferManager dataTransferManager;
	
	public void setDataTransferManager(DataTransferManager dataTransferManager) {
		this.dataTransferManager = dataTransferManager;
	}
	
	public void setGsInfoManager(GsInfoManager gsInfoManager) {
		this.gsInfoManager = gsInfoManager;
	}
	
	public void setReviewCommentsDOM(ReviewCommentsDOM reviewCommentsDOM) {
		this.reviewCommentsDOM = reviewCommentsDOM;
	}
	
	public void setBuisnessValidationManager(
			BuisnessValidationManager buisnessValidationManager) {
		this.buisnessValidationManager = buisnessValidationManager;
	}
	
	public void setGenericVisaWF(GenericVisaWF genericVisaWF) {
		this.genericVisaWF = genericVisaWF;
	}
	

	public void setGsEmployeeDetailsManager(
			GSEmployeeDetailsManager gsEmployeeDetailsManager) {
		this.gsEmployeeDetailsManager = gsEmployeeDetailsManager;
	}
	
	public void settTscClientCompanyDOM(
			TTscClientCompanyDOM tTscClientCompanyDOM) {
		this.tTscClientCompanyDOM = tTscClientCompanyDOM;
	}
	
	public void setFnpManager(FNPManager fnpManager) {
		this.fnpManager = fnpManager;
	}
	
	public void setTaskAndNotificationsManager(
			TaskAndNotificationsManager taskAndNotificationsManager) {
		this.taskAndNotificationsManager = taskAndNotificationsManager;
	}
	
	public void setUserDomainObjectManager(
			UserDomainObjectManager userDomainObjectManager) {
		this.userDomainObjectManager = userDomainObjectManager;
	}
	
	public void setAppMetaDataDOM(AppMetaDataDOM appMetaDataDOM) {
		this.appMetaDataDOM = appMetaDataDOM;
	}
	
	public void setFileStorageManager(FileStorageManager fileStorageManager) {
		this.fileStorageManager = fileStorageManager;
	}
	
	protected void transferDataToGS(AppMetaData appMetaData, UserVO userVO, String coLicNo) throws Exception{
		if(userVO.isAdmin()){
			TransferDataVO transferDataVO = new TransferDataVO();
			transferDataVO.setCompanyLicenseNo(coLicNo);
			transferDataVO.setAppMetaData(appMetaData);
			try{
				dataTransferManager.transferAppDateToOfflineSystem(transferDataVO);
			} catch(Exception  e){
				e.printStackTrace();
				fnpManager.cancelPayment(appMetaData.getApplicationId().toString(), userVO.getUsername(),
						appMetaData.getPaymentAdviceNo(),appMetaData.getClientRefNo());
				if(appMetaData.getBgPaymentAdviceNo()!=null){
					fnpManager.cancelPayment(appMetaData.getApplicationId().toString(), userVO.getUsername(), 
							appMetaData.getBgPaymentAdviceNo(),appMetaData.getClientRefNo());
					if(appMetaData.getProcessCode().equals(Process.PROCESS_EMPLOYMENT_VISA)){
						gsInfoManager.removeEmpVisaBG(coLicNo, userVO.getUsername());
					} else if(appMetaData.getProcessCode().equals(Process.PROCESS_VISIT_VISA)){
						gsInfoManager.removeVisitVisaBG(coLicNo, userVO.getUsername());
					}
				}
				throw new Exception(e);
			}
		}
	}
	
}
